package jdbc;

import util.DBUtil;

import java.sql.*;
import java.util.stream.Stream;

/**
 * @author oldliu
 * @since 1.0
 */
public class QueryTotal {
    public static void main(String[] args) {
        //总共有多少个学生
        Connection connection = DBUtil.get();
        PreparedStatement ps = null;
        ResultSet rs = null;
        String sql = "select count(stuno) from s_student";
        try {
            ps = connection.prepareStatement(sql);
            rs = ps.executeQuery();
            if (rs.next()) {
                //int count = rs.getInt("count(stuno)");
                int count = rs.getInt(1);
                System.out.println(count);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DBUtil.close(rs, ps, connection);
        }
    }
}
